feat(server-subscriptions): expose flatMapMerge concurrency for websocket subscriptions#2175
Merged
samuelAndalon merged 1 commit intoMay 18, 2026
Conversation
…cket subscriptions Previously GraphQLWebSocketServer.handleSubscription piped the inbound client message flow through flatMapMerge with no explicit concurrency, so it defaulted to the kotlinx DEFAULT_CONCURRENCY of 16. A single websocket session holding more than 16 in-flight subscriptions silently back-pressured every subsequent message on the channel - including ping, complete, and new subscribe - until one of the 16 completed, causing 17th-and-later subscribes to look hung. Expose the concurrency as a configurable value threaded through the three construction paths (raw GraphQLWebSocketServer, Ktor subclass, Spring subclass) and both server configurations (Ktor KtorSubscriptionConfiguration, Spring SubscriptionConfigurationProperties). Default remains 16 so existing callers see no behaviour change; raising it (or Int.MAX_VALUE) avoids the hang described in the issue. A new regression test constructs the in-memory subscription server with subscriptionConcurrency=1 and verifies that two back-to-back subscribe messages are serialised (all first-id responses arrive before any second-id response), which would fail under the previous implicit default.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
📝 Description
GraphQLWebSocketServer.handleSubscriptionpipes the inbound client-messageflow through
flatMapMerge { ... }without an explicitconcurrencyargument,so it falls back to the kotlinx
DEFAULT_CONCURRENCY = 16. A single websocketsession holding more than 16 in-flight subscriptions silently back-pressures
every subsequent inbound message on the underlying flow — including
ping,complete, and additionalsubscribemessages — until one of the 16 in-flightmessages completes. The 17th-and-later subscribes therefore look hung from the
client's perspective even though the transport is healthy.
This change exposes the concurrency as a configurable value, threaded through
the three construction paths and both server configurations:
GraphQLWebSocketServer— adds a final constructor parametersubscriptionConcurrency: Int = DEFAULT_WS_SUBSCRIPTION_CONCURRENCY(top-level
const val = 16), used as theconcurrencyargument toflatMapMerge.KtorGraphQLWebSocketServer— forwards a matching parameter to thesuperclass constructor.
KtorSubscriptionConfiguration— readsgraphql.server.subscription.concurrencyfromApplicationConfigwith thesame default;
GraphQL.ktwires it into the Ktor handler.SubscriptionWebSocketHandler(Spring) — forwards a matching parameter tothe superclass constructor.
SubscriptionConfigurationProperties— addssubscriptionConcurrency: Int = DEFAULT_WS_SUBSCRIPTION_CONCURRENCYas atrailing, defaulted field (preserves data-class binary compatibility);
SubscriptionGraphQLWsAutoConfigurationwires it through.Defaults are unchanged (16), so existing callers see identical behaviour. Users
who hold many simultaneous subscriptions per session can now raise the value
(e.g.
Int.MAX_VALUE) to avoid the back-pressure hang described in the issue.A new regression test
(
verify subscription flow honors configured concurrency) constructs thein-memory subscription server with
subscriptionConcurrency = 1and sends twoback-to-back
subscribemessages. Under the previous implicit default the twosubscriptions would interleave; with
concurrency = 1the assertion is thatall four responses for the first subscription id (3 ×
next+complete)arrive before any response for the second, which is observable and would have
been impossible without exposing the knob.
The scope is intentionally narrow: only the plumbing and default are changed.
No change to
TOO_MANY_REQUESTShandling, no change to graphql-ws protocolsemantics, no new public types beyond the constant and the trailing
parameters.
🔗 Related Issues
Closes #2018